//
//  CQTitleSwitchTableViewCell.m
//  TSListDemo
//
//  Created by qian on 2020/11/18.
//  Copyright © 2020 dvlproad. All rights reserved.
//

#import "CQTitleSwitchTableViewCell.h"

@interface CQTitleSwitchTableViewCell () {
    
}
@property (nonatomic, strong) UISwitch *swth;

@end

@implementation CQTitleSwitchTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

#pragma mark - Setter
- (void)setTitle:(NSString *)title {
    _title = title;
    self.textLabel.text = title;
}

- (void)setSwthOn:(BOOL)swthOn {
    _swthOn = swthOn;
    self.swth.on = swthOn;
}

#pragma mark - SetupViews
- (void)setupViews {
    UISwitch *swth = [[UISwitch alloc] init];
    [swth addTarget:self action:@selector(swthValueChange:) forControlEvents:UIControlEventValueChanged];
    self.accessoryView = swth;
    
    self.swth = swth;
}

- (void)swthValueChange:(UISwitch *)swth {
    BOOL isOn = swth.on;
    !self.valueChangeBlock ?: self.valueChangeBlock(isOn);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
